package com.stockz.ui.swing.charting.util;

import java.awt.Dimension;

import com.stockz.ui.swing.charting.view.StockChartPanel;
import com.stockz.ui.swing.charting.view.StockChartPanelState;
import com.stockz.ui.swing.charting.view.StockChartPanelStructure;

public class SetStockChartPanelSizeUtil {
	
	public static void setStockChartPanelSize(StockChartPanel stockChartPanel) {
			StockChartPanelState state = stockChartPanel.getStockChartPanelState();
			StockChartPanelStructure structure = stockChartPanel.getStockChartPanelStructure();
			
			int width = 0;
			int height = stockChartPanel.getHeight();
			if(state.getBarList() != null && !state.getBarList().isEmpty()){
				width = state.getBarList().size()*state.getTimeUnitSpace() 
						+ structure.getVoidSpaceLeftWidth() + structure.getVoidSpaceRightWidth()
						+ structure.getAxisPriceWidth() + structure.getAxisVolumeWidth();
			}else{
				width = stockChartPanel.getPreferredSize().width - stockChartPanel.getView().getScrollPane().getVerticalScrollBar().getWidth();
			}
			Dimension dimension = new Dimension(width,height);
			stockChartPanel.setPreferredSize(dimension);
			stockChartPanel.setSize(dimension);
	}
}
